package com.qifan.energy.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.qifan.energy.R;
import com.qifan.energy.adapter.ImageNetAdapter;
import com.qifan.energy.adapter.QuickItem2Adapter;
import com.qifan.energy.bean.model.HomeQuickItem;
import com.qifan.energy.bean.result.HomeListResult;
import com.qifan.energy.mvp.callback.IOnClickIndexListener;
import com.qifan.energy.util.ToastUtils;
import com.qifan.energy.util.UIUtils;
import com.youth.banner.Banner;
import com.youth.banner.indicator.CircleIndicator;
import com.youth.banner.transformer.AlphaPageTransformer;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class CustomQuickView extends LinearLayout {

    //自定义变量
    private RecyclerView recyclerView;
    private List<HomeQuickItem> dataList = new ArrayList(){{
        add(new HomeQuickItem("新品上架",R.mipmap.icon_home_quick1));
        add(new HomeQuickItem("奶粉辅食",R.mipmap.icon_home_quick2));
        add(new HomeQuickItem("喂养用品",R.mipmap.icon_home_quick3));
        add(new HomeQuickItem("纸尿裤",R.mipmap.icon_home_quick4));
        add(new HomeQuickItem("洗护用品",R.mipmap.icon_home_quick5));
        add(new HomeQuickItem("睡袋棉品",R.mipmap.icon_home_quick6));
        add(new HomeQuickItem("童装童鞋",R.mipmap.icon_home_quick7));
        add(new HomeQuickItem("童车童床",R.mipmap.icon_home_quick8));
        add(new HomeQuickItem("玩具早教",R.mipmap.icon_home_quick9));
        add(new HomeQuickItem("宝妈专区",R.mipmap.icon_home_quick10));
    }};

    /* 定义接口 */
    private IOnClickIndexListener listener = new IOnClickIndexListener() {
        @Override
        public void onClick(int index) {

        }
    };

    /* 对外提供 */
    public void setOnClickIndexListener(IOnClickIndexListener listener) {
        this.listener = listener;
    }

    public CustomQuickView(Context context) {
        super(context);

        /* 初始化UI */
        View inflate = inflate(getContext(), R.layout.item_home_quick, this);
        QuickItem2Adapter adapter = new QuickItem2Adapter(dataList);
        adapter.setOnItemClickListener((a,v,p) -> {
            if (listener != null) {
                listener.onClick(p);
            }
        });
        recyclerView = inflate.findViewById(R.id.recycler_view);
        final GridLayoutManager layoutManager = new GridLayoutManager(context,5);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
    }

    public CustomQuickView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomQuickView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
}
